# commonTest 目录的 CMakeLists.txt

# 收集 commonTest 目录下的所有测试源文件
file(GLOB_RECURSE COMMON_TEST_SOURCES "*.hpp" "*.cpp")

# 创建测试套件
add_executable(commonTestSuite ${COMMON_TEST_SOURCES})

# 根据 GoogleTest 源自何处，使用不同的链接方式
find_package(GTest REQUIRED)
if(GTest_FOUND)
    # 使用系统安装的 Google Test
    target_link_libraries(commonTestSuite
        PRIVATE
        GTest::GTest
        GTest::Main
        common_lib
        model_lib
        sqlite_orm
        ${Boost_LIBRARIES}
    )
else()
    # 使用项目内配置的 Google Test
    if(TARGET gtest AND TARGET gtest_main)
        target_link_libraries(commonTestSuite
            PRIVATE
            gtest
            gtest_main
            common_lib
            model_lib
            sqlite_orm
            ${Boost_LIBRARIES}
        )
    else()
        message(FATAL_ERROR "Google Test targets 'gtest' and 'gtest_main' not found. Please ensure Google Test is properly configured.")
    endif()
endif()

# 设置包含目录
target_include_directories(commonTestSuite
    PRIVATE
    ${CMAKE_SOURCE_DIR}/src/common/include
    ${CMAKE_SOURCE_DIR}/src/model/include
)

# 将测试归类
set_target_properties(commonTestSuite PROPERTIES FOLDER "Tests/CommonTests")

include(GoogleTest)
# 添加为测试
gtest_discover_tests(commonTestSuite)
